package com.yuanwushe.blue.onceandroid;

import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.yuanwushe.blue.adapter.FruitAdapter;
import com.yuanwushe.blue.models.Fruit;

import java.util.ArrayList;
import java.util.List;

public class RecyclerActivity extends BaseActivity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_recycler);
        ActionBar actionBar = getSupportActionBar();
        if (actionBar != null) {
            actionBar.hide();
        }
        init();
    }

    private void init() {
        RecyclerView recyclerView = findViewById(R.id.relative);
        List<Fruit> list = initFruits();
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
        recyclerView.setLayoutManager(linearLayoutManager);
        RecyclerView.Adapter adapter = new FruitAdapter(list);
        recyclerView.setAdapter(adapter);
    }

    private List<Fruit> initFruits() {
        List<Fruit> fruits = new ArrayList<>();
        for (int i = 0; i < 3; i++) {
            Fruit a = new Fruit("苹果", "苹果的简介");
            fruits.add(a);
            Fruit b = new Fruit("香蕉", "香蕉的简介");
            fruits.add(b);
            Fruit c = new Fruit("草莓", "草莓的简介");
            fruits.add(c);
            Fruit d = new Fruit("荔枝", "荔枝的简介");
            fruits.add(d);
            Fruit e = new Fruit("樱桃", "樱桃的简介");
            fruits.add(e);
            Fruit f = new Fruit("甘蔗", "甘蔗的简介");
            fruits.add(f);
            Fruit g = new Fruit("桃", "桃的简介");
            fruits.add(g);
        }
        return fruits;
    }

}
